﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConnectToDatabase
{
    class Program
    {
        static void Main(string[] args)
        {

            var conString = "server=.;database=bbtest;Trusted_Connection=SSPI";
            SqlConnection connection = new SqlConnection(conString);
            connection.Open();
            SqlCommand command = new SqlCommand("select * from Users", connection);
            var cmdString = "select * from Student";
            var reader = command.ExecuteReader();
            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}",reader[0],reader[1],reader[2]);
                
            }

            connection.Close();
            DataTable table = new DataTable();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdString,conString);
            dataAdapter.Fill(table);
            foreach (DataRow item in table.Rows)
            {
                Console.WriteLine(item["Id"]);
            }


            
            command.CommandText = "insert into Student values('xiaoyou',100)";
            command.ExecuteNonQuery();



            command.CommandText = "delete from Student";
            command.ExecuteNonQuery();


            command.CommandText = "update Student set Name=xiaohong";
            command.ExecuteNonQuery();











        }
    }
}
